<?php
/**
 * TODO: Copyright
 */
/**
 * ShiftExchange Service class for communication between controllers and 
 * persistent storage
 */
class Core_Service_ShiftExchange extends RedCross_Service_ServiceAbstract
{
    /**
     * Constructor
     * @param Core_Gateway_ShiftExchange $gateway
     */
    public function __construct(Core_Gateway_ShiftExchange $gateway)
    {
        parent::__construct($gateway, 'Core_Model_ShiftExchange');
    }

    public function create($sourceMemberId, $targetMemberId, $shiftRoleId) {
        $shiftExchange = new Core_Model_ShiftExchange();
        $shiftExchange->source_member_id = $sourceMemberId;
        $shiftExchange->target_member_id = $targetMemberId;
        $shiftExchange->shift_role_id = $shiftRoleId;

        if ($shiftExchange->save() !== false) {
            return $shiftExchange;
        }

        return false;
    }

    public function fetchAllForShift($shiftId) {
        return $this->getGateway()->fetchAllForShift($shiftId);
    }

    public function fetchAllUnhandledForShift($shiftId) {
        return $this->getGateway()->fetchAllUnhandledForShift($shiftId);
    }

    public function fetchAllHandledForShift($shiftId) {
        return $this->getGateway()->fetchAllHandledForShift($shiftId);
    }

    public function fetchAllUnhandled() {
        return $this->getGateway()->fetchAllUnhandled();
    }

    public function fetchById($shiftExchangeId) {
        return $this->getGateway()->fetchById($shiftExchangeId);
    }
}

?>
